import type { MenuParams, MenuTree, Menu } from '@/models/menu'
import type { PageDto, CommonResult, CommonPage } from '@/models/request'
import request from '@/utils/request'

export const fetchTreeList = () => request<CommonResult<MenuTree[]>>({ url: '/menu/treeList', method: 'get' })

export function fetchList(parentId: number, params: PageDto) {
  return request<CommonPage<Menu>>({
    url: '/menu/list/' + parentId,
    method: 'get',
    params: params,
  })
}

export function deleteMenu(id: number) {
  return request<CommonResult>({
    url: '/menu/delete/' + id,
    method: 'post',
  })
}

export function createMenu(data: MenuParams) {
  return request<CommonResult>({
    url: '/menu/create',
    method: 'post',
    data: data,
  })
}

export function updateMenu(id: number, data: MenuParams) {
  return request<CommonResult>({
    url: '/menu/update/' + id,
    method: 'post',
    data: data,
  })
}

export function getMenu(id: number) {
  return request<CommonResult<Menu>>({
    url: '/menu/' + id,
    method: 'get',
  })
}

export function updateHidden(id: number, params: { hidden: number }) {
  return request<CommonResult>({
    url: '/menu/updateHidden/' + id,
    method: 'post',
    params: params,
  })
}
